Adding some more judges, here and there.
[and.git] / lib / Mi manual de algoritmos / version_maraton_nacional_2008 / src / number_theory / bigmod.tex
blob1e509363af5690814232c893454505ee6924eabf
1 % Generator: GNU source-highlight, by Lorenzo Bettini, http://www.gnu.org/software/src-highlite
3 {\ttfamily \raggedright {
4 \noindent
5 \mbox{}\textit{\textcolor{Brown}{//retorna\ (b\textasciicircum{}p)mod(m)}} \\
6 \mbox{}\textit{\textcolor{Brown}{//\ 0\ $<$=\ b,p\ $<$=\ 2147483647}} \\
7 \mbox{}\textit{\textcolor{Brown}{//\ 1\ $<$=\ m\ $<$=\ 46340}} \\
8 \mbox{}\textcolor{ForestGreen}{long}\ \textbf{\textcolor{Black}{f}}\textcolor{BrickRed}{(}\textcolor{ForestGreen}{long}\ b\textcolor{BrickRed}{,}\ \textcolor{ForestGreen}{long}\ p\textcolor{BrickRed}{,}\ \textcolor{ForestGreen}{long}\ m\textcolor{BrickRed}{)}\textcolor{Red}{\{} \\
9 \mbox{}\ \ \textcolor{ForestGreen}{long}\ mask\ \textcolor{BrickRed}{=}\ \textcolor{Purple}{1}\textcolor{BrickRed}{;} \\
10 \mbox{}\ \ \textcolor{ForestGreen}{long}\ pow2\ \textcolor{BrickRed}{=}\ b\ \textcolor{BrickRed}{\%}\ m\textcolor{BrickRed}{;} \\
11 \mbox{}\ \ \textcolor{ForestGreen}{long}\ r\ \textcolor{BrickRed}{=}\ \textcolor{Purple}{1}\textcolor{BrickRed}{;} \\
12 \mbox{} \\
13 \mbox{}\ \ \textbf{\textcolor{Blue}{while}}\ \textcolor{BrickRed}{(}mask\textcolor{BrickRed}{)}\textcolor{Red}{\{} \\
14 \mbox{}\ \ \ \ \textbf{\textcolor{Blue}{if}}\ \textcolor{BrickRed}{(}p\ \textcolor{BrickRed}{\&}\ mask\textcolor{BrickRed}{)} \\
15 \mbox{}\ \ \ \ \ \ r\ \textcolor{BrickRed}{=}\ \textcolor{BrickRed}{(}r\ \textcolor{BrickRed}{*}\ pow2\textcolor{BrickRed}{)}\ \textcolor{BrickRed}{\%}\ m\textcolor{BrickRed}{;} \\
16 \mbox{}\ \ \ \ pow2\ \textcolor{BrickRed}{=}\ \textcolor{BrickRed}{(}pow2\textcolor{BrickRed}{*}pow2\textcolor{BrickRed}{)}\ \textcolor{BrickRed}{\%}\ m\textcolor{BrickRed}{;} \\
17 \mbox{}\ \ \ \ mask\ \textcolor{BrickRed}{$<$$<$=}\ \textcolor{Purple}{1}\textcolor{BrickRed}{;} \\
18 \mbox{}\ \ \textcolor{Red}{\}} \\
19 \mbox{}\ \ \textbf{\textcolor{Blue}{return}}\ r\textcolor{BrickRed}{;} \\
20 \mbox{}\textcolor{Red}{\}} \\
22 } \normalfont\normalsize